﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace NASA.BeAMartian.TagGraph.Surveying
{

    public class ImageFeatures : ObservableCollection<ImageFeature>
    {
        public bool ContainsLandTags = false;
        public bool ContainsSkyTags = false;
        public bool ContainsRoverTags = false;
        public string RoverName = "";

        public string GetTags()
        {
            string s = "";

            foreach (ImageFeature i in this)
            {
                if (s.Length > 0)
                    s += ", ";
                s += i.Feature;
            }

            return s;
        }

        public void RemoveTags(ImageTagTypes type)
        {
            for (int i = Count - 1; i >= 0; i--)
            {
                if (this[i].TagType == type)
                    RemoveAt(i);
            }

            switch (type)
            {
                case ImageTagTypes.Land:
                    ContainsLandTags = false;
                    break;
                case ImageTagTypes.Sky:
                    ContainsSkyTags = false;
                    break;
                case ImageTagTypes.Rover:
                    ContainsRoverTags = false;
                    break;
            }
        }

        public void RemoveTags(string type)
        {
            switch (type)
            {
                case "Land":
                    RemoveTags(ImageTagTypes.Land);
                    break;
                case "Sky":
                    RemoveTags(ImageTagTypes.Sky);
                    break;
                case "Rover":
                    RemoveTags(ImageTagTypes.Rover);
                    break;
            }
        }

        public void RefreshTags(string type, string roverName)
        {
            ImageFeatures i = null;

            switch (type)
            {
                case "Land":
                    RoverName = roverName;
                    i = new ImageTagsLand(RoverName);
                    RemoveTags(ImageTagTypes.Land);
                    break;
                case "Sky":
                    i = new ImageTagsSky();
                    RemoveTags(ImageTagTypes.Sky);
                    break;
                case "Rover":
                    i = new ImageTagsRover();
                    RemoveTags(ImageTagTypes.Rover);
                    break;
            }

            AddTags(i);
        }

        public void AddTags(ImageFeatures i)
        {
            foreach (ImageFeature f in i)
            {
                Add(f);
            }

            if (i.Count == 0)
                return;

            switch (i[0].TagType)
            {
                case ImageTagTypes.Land:
                    ContainsLandTags = true;
                    break;
                case ImageTagTypes.Sky:
                    ContainsSkyTags = true;
                    break;
                case ImageTagTypes.Rover:
                    ContainsRoverTags = true;
                    break;
            }
        }

        public void Reset()
        {
            Clear();
            ContainsLandTags = false;
            ContainsRoverTags = false;
            ContainsSkyTags = false;
        }

        protected string img(string imgName)
        {
            return String.Format("http://beamdownload.blob.core.windows.net/media/Rover/{0}", imgName);
        }
    }
	
}
